```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java线程池核心线程机制解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8fafc;
            color: #1e293b;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
        }
        .code-block {
            background: #1e293b;
            border-left: 4px solid #3b82f6;
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .highlight-box {
            position: relative;
        }
        .highlight-box::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 4px;
            height: 100%;
            background: #3b82f6;
            border-radius: 2px;
        }
        .drop-cap::first-letter {
            float: left;
            font-size: 3.5em;
            line-height: 0.8;
            margin: 0.1em 0.15em 0 0;
            color: #3b82f6;
            font-weight: 700;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold leading-tight mb-4">深入解析Java线程池<br>核心线程机制</h1>
                    <p class="text-xl text-blue-100 mb-8">探索ThreadPoolExecutor中核心线程的设计哲学与实现原理</p>
                    <div class="flex space-x-4">
                        <div class="flex items-center">
                            <i class="fas fa-clock text-blue-200 mr-2"></i>
                            <span class="text-blue-100">5分钟阅读</span>
                        </div>
                        <div class="flex items-center">
                            <i class="fas fa-code text-blue-200 mr-2"></i>
                            <span class="text-blue-100">实战代码示例</span>
                        </div>
                    </div>
                </div>
                <div class="md:w-1/2 flex justify-center">
                    <div class="relative">
                        <div class="absolute -top-6 -left-6 w-24 h-24 bg-blue-400 rounded-full opacity-20"></div>
                        <div class="absolute -bottom-6 -right-6 w-24 h-24 bg-blue-400 rounded-full opacity-20"></div>
                        <div class="relative bg-white text-gray-800 p-6 rounded-lg shadow-xl w-80">
                            <div class="flex items-center mb-4">
                                <div class="w-3 h-3 bg-red-500 rounded-full mr-2"></div>
                                <div class="w-3 h-3 bg-yellow-500 rounded-full mr-2"></div>
                                <div class="w-3 h-3 bg-green-500 rounded-full"></div>
                            </div>
                            <div class="bg-gray-100 p-4 rounded">
                                <pre class="text-xs text-gray-800 overflow-x-auto">
<span class="text-blue-600">ThreadPoolExecutor</span> executor = <span class="text-purple-600">new</span> ThreadPoolExecutor(
  <span class="text-emerald-600">5</span>, <span class="text-gray-500">// corePoolSize</span>
  <span class="text-emerald-600">10</span>, <span class="text-gray-500">// maxPoolSize</span>
  <span class="text-emerald-600">60</span>, TimeUnit.<span class="text-blue-600">SECONDS</span>,
  <span class="text-purple-600">new</span> LinkedBlockingQueue<>()
);</pre>
                            </div>
                            <div class="mt-4 text-sm text-gray-600">
                                <div class="flex items-center mb-2">
                                    <i class="fas fa-circle text-blue-500 mr-2 text-xs"></i>
                                    <span>核心线程始终保持活跃</span>
                                </div>
                                <div class="flex items-center">
                                    <i class="fas fa-circle text-purple-500 mr-2 text-xs"></i>
                                    <span>减少线程创建销毁开销</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="container mx-auto max-w-5xl px-4 md:px-0 py-12">
        <!-- Introduction -->
        <section class="mb-16">
            <div class="flex items-center mb-6">
                <div class="w-12 h-1 bg-blue-500 mr-4"></div>
                <h2 class="text-2xl font-bold text-gray-800">核心机制概述</h2>
            </div>
            <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                <div class="p-8">
                    <p class="drop-cap text-gray-700 leading-relaxed mb-6">在Java并发编程中，ThreadPoolExecutor的核心线程机制是线程池高效运作的关键设计。核心线程作为线程池的基础设施，即使在空闲状态下也不会被终止，这种设计巧妙地平衡了资源利用率和响应速度。</p>
                    
                    <div class="grid md:grid-cols-2 gap-6 mb-8">
                        <div class="bg-blue-50 p-6 rounded-lg highlight-box">
                            <h3 class="flex items-center text-lg font-semibold mb-3 text-blue-800">
                                <i class="fas fa-bolt text-blue-500 mr-2"></i>
                                核心线程定义
                            </h3>
                            <ul class="space-y-2 text-gray-700">
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-blue-500 mt-1 mr-2 flex-shrink-0"></i>
                                    <span>线程池中始终保持活动状态的最小线程数</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-blue-500 mt-1 mr-2 flex-shrink-0"></i>
                                    <span>通过corePoolSize参数配置</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-blue-500 mt-1 mr-2 flex-shrink-0"></i>
                                    <span>除非线程池关闭，否则不会终止</span>
                                </li>
                            </ul>
                        </div>
                        <div class="bg-blue-50 p-6 rounded-lg highlight-box">
                            <h3 class="flex items-center text-lg font-semibold mb-3 text-blue-800">
                                <i class="fas fa-cogs text-blue-500 mr-2"></i>
                                核心角色
                            </h3>
                            <ul class="space-y-2 text-gray-700">
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-blue-500 mt-1 mr-2 flex-shrink-0"></i>
                                    <span>处理提交给线程池的任务</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-blue-500 mt-1 mr-2 flex-shrink-0"></i>
                                    <span>保持活跃确保快速响应</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check-circle text-blue-500 mt-1 mr-2 flex-shrink-0"></i>
                                    <span>避免频繁创建销毁线程的开销</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Implementation Mechanism -->
        <section class="mb-16">
            <div class="flex items-center mb-6">
                <div class="w-12 h-1 bg-blue-500 mr-4"></div>
                <h2 class="text-2xl font-bold text-gray-800">实现机制剖析</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover mb-8">
                <div class="p-8">
                    <h3 class="text-xl font-semibold mb-4 text-gray-800">ThreadPoolExecutor内部机制</h3>
                    
                    <div class="mermaid mb-8">
                        graph TD
                            A[任务提交] --> B{核心线程是否空闲?}
                            B -->|是| C[分配任务给核心线程]
                            B -->|否| D{线程数<maxPoolSize?}
                            D -->|是| E[创建新线程处理]
                            D -->|否| F[任务加入工作队列]
                            C --> G[任务执行完成,线程保持活动]
                    </div>
                    
                    <div class="grid md:grid-cols-3 gap-4 mb-6">
                        <div class="bg-white border border-gray-200 rounded-lg p-4">
                            <div class="text-blue-500 mb-2">
                                <i class="fas fa-sliders-h text-2xl"></i>
                            </div>
                            <h4 class="font-semibold mb-2">参数配置</h4>
                            <p class="text-sm text-gray-600">通过corePoolSize设置核心线程数，最大线程数由maxPoolSize控制。</p>
                        </div>
                        <div class="bg-white border border-gray-200 rounded-lg p-4">
                            <div class="text-blue-500 mb-2">
                                <i class="fas fa-plus-circle text-2xl"></i>
                            </div>
                            <h4 class="font-semibold mb-2">线程创建</h4>
                            <p class="text-sm text-gray-600">线程池启动时创建核心线程，等待任务提交。</p>
                        </div>
                        <div class="bg-white border border-gray-200 rounded-lg p-4">
                            <div class="text-blue-500 mb-2">
                                <i class="fas fa-heartbeat text-2xl"></i>
                            </div>
                            <h4 class="font-semibold mb-2">线程保持</h4>
                            <p class="text-sm text-gray-600">核心线程在空闲时不会被终止，始终保持活动状态。</p>
                        </div>
                    </div>
                    
                    <h3 class="text-xl font-semibold mb-4 text-gray-800 mt-8">核心线程生命周期</h3>
                    <div class="relative h-2 bg-gray-200 rounded-full mb-6">
                        <div class="absolute h-2 bg-gradient-to-r from-blue-500 to-blue-300 rounded-full" style="width: 100%"></div>
                        <div class="absolute flex justify-between w-full -bottom-6">
                            <span class="text-sm text-gray-600">线程创建</span>
                            <span class="text-sm text-gray-600">任务执行</span>
                            <span class="text-sm text-gray-600">保持活跃</span>
                            <span class="text-sm text-gray-600">线程池关闭</span>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="bg-gray-900 rounded-xl overflow-hidden">
                <div class="flex items-center bg-gray-800 px-6 py-3">
                    <div class="flex space-x-2 mr-4">
                        <div class="w-3 h-3 rounded-full bg-red-500"></div>
                        <div class="w-3 h-3 rounded-full bg-yellow-500"></div>
                        <div class="w-3 h-3 rounded-full bg-green-500"></div>
                    </div>
                    <span class="text-gray-400 text-sm">CoreThreadDemo.java</span>
                </div>
                <div class="p-6 overflow-x-auto code-block">
                    <pre class="text-gray-300 text-sm"><code>
<span class="text-purple-400">import</span> java.util.concurrent.*;

<span class="text-purple-400">public class</span> <span class="text-blue-400">CoreThreadDemo</span> {
    <span class="text-purple-400">public static void</span> <span class="text-yellow-300">main</span>(String[] args) {
        <span class="text-gray-500">// 创建线程池，配置核心线程数</span>
        ThreadPoolExecutor executor = <span class="text-purple-400">new</span> ThreadPoolExecutor(
            <span class="text-emerald-400">5</span>,                      <span class="text-gray-500">// corePoolSize: 核心线程数</span>
            <span class="text-emerald-400">10</span>,                     <span class="text-gray-500">// maximumPoolSize: 最大线程数</span>
            <span class="text-emerald-400">60</span>,                     <span class="text-gray-500">// 非核心线程空闲时间</span>
            TimeUnit.<span class="text-blue-400">SECONDS</span>,      <span class="text-gray-500">// 时间单位</span>
            <span class="text-purple-400">new</span> LinkedBlockingQueue<>() <span class="text-gray-500">// 工作队列</span>
        );

        <span class="text-gray-500">// 提交20个任务到线程池</span>
        <span class="text-purple-400">for</span> (<span class="text-purple-400">int</span> i = <span class="text-emerald-400">0</span>; i &lt; <span class="text-emerald-400">20</span>; i++) {
            <span class="text-purple-400">final int</span> taskId = i;
            executor.<span class="text-yellow-300">submit</span>(() -> {
                System.<span class="text-blue-400">out</span>.println(<span class="text-orange-300">"Task "</span> + taskId + 
                    <span class="text-orange-300">" executed by: "</span> + Thread.<span class="text-yellow-300">currentThread</span>().<span class="text-yellow-300">getName</span>());
                <span class="text-purple-400">try</span> {
                    Thread.<span class="text-yellow-300">sleep</span>(<span class="text-emerald-400">2000</span>); <span class="text-gray-500">// 模拟任务执行</span>
                } <span class="text-purple-400">catch</span> (InterruptedException e) {
                    Thread.<span class="text-yellow-300">currentThread</span>().<span class="text-yellow-300">interrupt</span>();
                }
            });
        }

        <span class="text-gray-500">// 关闭线程池</span>
        executor.<span class="text-yellow-300">shutdown</span>();
    }
}</code></pre>
                </div>
            </div>
        </section>

        <!-- Advantages -->
        <section class="mb-16">
            <div class="flex items-center mb-6">
                <div class="w-12 h-1 bg-blue-500 mr-4"></div>
                <h2 class="text-2xl font-bold text-gray-800">核心线程的优势</h2>
            </div>
            
            <div class="grid md:grid-cols-3 gap-6">
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="text-blue-500 mb-4 text-4xl">
                            <i class="fas fa-tachometer-alt"></i>
                        </div>
                        <h3 class="text-xl font-semibold mb-3">性能优化</h3>
                        <p class="text-gray-600">通过保持核心线程活跃，避免了频繁创建和销毁线程的开销，显著提升了系统整体性能。</p>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="text-blue-500 mb-4 text-4xl">
                            <i class="fas fa-bolt"></i>
                        </div>
                        <h3 class="text-xl font-semibold mb-3">响应速度</h3>
                        <p class="text-gray-600">核心线程可以立即响应新任务，减少了任务排队等待时间，提高了系统响应能力。</p>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="text-blue-500 mb-4 text-4xl">
                            <i class="fas fa-chart-line"></i>
                        </div>
                        <h3 class="text-xl font-semibold mb-3">资源利用</h3>
                        <p class="text-gray-600">动态调整核心线程数可以更好地匹配系统负载，实现资源的最优配置。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Management -->
        <section>
            <div class="flex items-center mb-6">
                <div class="w-12 h-1 bg-blue-500 mr-4"></div>
                <h2 class="text-2xl font-bold text-gray-800">核心线程管理</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                <div class="p-8">
                    <div class="grid md:grid-cols-2 gap-8">
                        <div>
                            <h3 class="text-xl font-semibold mb-4 flex items-center">
                                <i class="fas fa-sliders-h text-blue-500 mr-2"></i>
                                动态调整
                            </h3>
                            <p class="text-gray-700 mb-4">ThreadPoolExecutor提供了setCorePoolSize方法，允许在运行时动态调整核心线程数：</p>
                            <div class="bg-gray-100 p-4 rounded-lg mb-4">
                                <pre class="text-sm text-gray-800"><span class="text-blue-600">executor</span>.<span class="text-purple-600">setCorePoolSize</span>(<span class="text-emerald-600">8</span>);</pre>
                            </div>
                            <p class="text-gray-700">当增加核心线程数时，会立即创建新线程直至达到新的核心线程数；减少时，空闲线程会在下次空闲时终止。</p>
                        </div>
                        
                        <div>
                            <h3 class="text-xl font-semibold mb-4 flex items-center">
                                <i class="fas fa-power-off text-blue-500 mr-2"></i>
                                线程池关闭
                            </h3>
                            <p class="text-gray-700 mb-4">关闭线程池时，所有线程（包括核心线程）都会被终止：</p>
                            <div class="grid gap-4">
                                <div class="bg-gray-100 p-4 rounded-lg">
                                    <pre class="text-sm text-gray-800"><span class="text-blue-600">executor</span>.<span class="text-purple-600">shutdown</span>(); <span class="text-gray-600">// 优雅关闭，等待任务完成</span></pre>
                                </div>
                                <div class="bg-gray-100 p-4 rounded-lg">
                                    <pre class="text-sm text-gray-800"><span class="text-blue-600">executor</span>.<span class="text-purple-600">shutdownNow</span>(); <span class="text-gray-600">// 立即关闭，中断运行中的线程</span></pre>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="mt-8 pt-6 border-t border-gray-200">
                        <h3 class="text-xl font-semibold mb-4 flex items-center">
                            <i class="fas fa-lightbulb text-blue-500 mr-2"></i>
                            最佳实践建议
                        </h3>
                        <ul class="space-y-3 text-gray-700">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-blue-500 mt-1 mr-2 flex-shrink-0"></i>
                                <span>根据系统负载合理设置corePoolSize，通常设置为CPU核心数的1-2倍</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-blue-500 mt-1 mr-2 flex-shrink-0"></i>
                                <span>对短时间任务密集型的应用，可适当增加核心线程数</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-blue-500 mt-1 mr-2 flex-shrink-0"></i>
                                <span>对长时间任务，应控制核心线程数避免资源浪费</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-blue-500 mt-1 mr-2 flex-shrink-0"></i>
                                <span>结合工作队列类型和大小综合考虑线程池配置</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>
    </div>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: false,
                htmlLabels: true,
                curve: 'basis'
            }
        });
        
        // 微交互效果
        document.querySelectorAll('.card-hover').forEach(card => {
            card.addEventListener('mouseenter', function() {
                this.style.boxShadow = '0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)';
            });
            card.addEventListener('mouseleave', function() {
                this.style.boxShadow = '';
            });
        });
    </script>
</body>
</html>
```